#include <iostream>
#include <queue>
#include <algorithm>
#include <cstring>
typedef long long ll;
using namespace std;
int df[10][10];
int bs[10][10];
struct node{
    int x;
    int y;
};
queue<node> q;

void init(){
    memset(bs, 0, sizeof(bs));
    int cou = 1;
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            df[i][j]=cou++;
            cout<<df[i][j]<<" ";
        }
        cout<<endl;
    }
}
void bfs(node n){
    q.push(n);
    bs[n.x][n.y] = 1;
    while (!q.empty()){
        node a = q.front();
        q.pop();
        if (a.y<10-1&&!bs[a.x][a.y+1]){
            cout<< df[a.x][a.y+1]<<" ";
            node b;b.x=a.x;b.y=a.y+1;
            q.push(b);
            bs[b.x][b.y]=1;
        }
        if (a.x<10-1&&!bs[a.x+1][a.y]){
            cout<< df[a.x+1][a.y]<<" ";
            node b;
            b.x=a.x+1;
            b.y=a.y;
            q.push(b);
            bs[b.x][b.y]=1;
        }
        if (a.y>0&&!bs[a.x][a.y-1]){
            cout<< df[a.x][a.y-1]<<" ";
            node b;
            b.x=a.x;
            b.y=a.y-1;
            q.push(b);
            bs[b.x][b.y]=1;
        }
        if (a.x>0&&!bs[a.x-1][a.y]){
            cout<< df[a.x-1][a.y]<<" ";
            node b;
            b.x=a.x-1;
            b.y=a.y;
            q.push(b);
            bs[b.x][b.y]=1;
        }

    }
}
int main(){
    init();
    node a;
    a.x=5;
    a.y=2;
    bfs(a);
    return 0;
}